<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="com.ahp.bean.EvaleObject"%>
<%@page import="java.util.List"%>
<%@ include file="../include/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>为任务配置评估对象</title>
<script type="text/javascript" src="<%=path %>/js/jquery-1.3.2.js"></script>
<link rel="stylesheet" href="<%=path%>/style/style_manage.css" type="text/css"></link>
<style type="text/css">
.added{border: 1px solid gray; margin: 1em 1em; padding: 5px 8px;}
.delSpan{cursor: pointer;}
div{line-height: 150%;}
</style>
<script type="text/javascript">
addObject = function(current){
	$this = $(current);
	var evaleName = $("#evaleName").val();
	if(evaleName.length > 0){
		$this.attr("disabled","disabled");
		$.post("<%=path %>/task/addEvaleObject.action",{
				"evaleObject.tast.tastId":$("#taskId").val(),
				"evaleObject.name":$("#evaleName").val(),
				d:new Date().getMilliseconds()
			},function(data){
				var obj = eval("("+data+")");
				if(obj.result=="right"){
					$("#result").text("添加成功");
					$(".objectItems").append("<span class='added' id='addedId"+obj.id+"'>"+$("#evaleName").val()+" <span onclick=\"delObj('"+obj.id+"')\" class=\"delSpan\">删除</span></span>");
					$("#evaleName").val("");
					$this.removeAttr("disabled");
				}else{
					$("#result").text("添加失败请重试");
					$this.removeAttr("disabled");
				}
		});
	}else{
		$("#result").text("请填写评估对象名称。");
		return false;
	}
}
delObj = function(id){
	$.post("<%=path%>/task/delEvaleObject.action",{ "evaleObject.evaleId": id ,d:new Date().getMilliseconds()},function(data){
		if(data=="true"){
			$("#addedId"+id).hide();	
		}else{
			$("#result").text("删除失败请重试");
		}
	});
}
next = function(){
	if($(".added").size() > 0){
		window.location.href="<%=path%>/mod/searchMod.action";
	}else{
		$("#result").text("请添加评估对象");
	}
}
</script>
</head>
<body>
<div id="management">
<h1 style="position: relative;">添加评估对象</h1>
	<div id="result" style="color:red;"></div>
	<input type="hidden" name="task.id" id="taskId" value="${param["evaleObject.tast.tastId"] }"/>
	<div class="objects" style="margin: 10px 20px;">
		已添加评估对象：<div class="objectItems"><%
		if(request.getAttribute("evaleObjs")!=null){
			List<EvaleObject> evaleObjectList = (List<EvaleObject>)request.getAttribute("evaleObjs");
			for (EvaleObject evaleObject : evaleObjectList) {
				%><span class='added' id="addedId<%=evaleObject.getEvaleId() %>"><%=evaleObject.getName() %> <span onclick="delObj('<%=evaleObject.getEvaleId() %>')" class="delSpan">删除</span></span><%
			}
		}
		%></div>
	</div>
	<div>
		新增评估对象名：<input type="text" name="task.name" id="evaleName" value=""/>
		<input type="button" value="添加" id="addButton" onclick="addObject(this);" />
	</div>
	<div>
		<input type="button" value="下一步" onclick="next();" />
	</div>
</div>
</body>
</html>